var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/defineProperty")), e = require("../../services/api.js");

function a(t, e) {
    var a = Object.keys(t);
    if (Object.getOwnPropertySymbols) {
        var n = Object.getOwnPropertySymbols(t);
        e && (n = n.filter(function(e) {
            return Object.getOwnPropertyDescriptor(t, e).enumerable;
        })), a.push.apply(a, n);
    }
    return a;
}

Page({
    data: {
        tabs: [ "全部", "未支付", "已完成", "已关闭" ],
        active: 0,
        pageNum: [ 1, 1, 1, 1, 1 ],
        pageTotal: [ 0, 0, 0, 0, 0 ],
        lists: Array(5).fill([])
    },
    onLoad: function(t) {
        this.getLists();
    },
    tabChangeHandle: function(t) {
        var e = this;
        this.setData({
            active: t.detail.current
        }, function() {
            e.getLists();
        });
    },
    uppz: function(t) {
        var e = t.currentTarget.dataset.id;
        this.doPay(e);
    },
    qxdd: function(t) {
        var a = this, n = t.currentTarget.dataset.id;
        wx.showModal({
            title: "提示",
            content: "确认取消订单？",
            success: function(t) {
                t.confirm && (0, e.orderDelet)({
                    order_sn: n
                }).then(function(t) {
                    200 === t.data.code ? (wx.showToast({
                        title: "删除订单",
                        mask: !0
                    }), a.getLists()) : wx.showModal({
                        title: "提示",
                        content: t.data.message,
                        showCancel: !1
                    });
                });
            }
        });
    },
    doPay: function(n) {
        var o = this;
        wx.showLoading({
            title: "正在创建订单",
            mask: !0
        }), (0, e.createGoodsPay)({
            pay_type: 1,
            trade_type: "mini_program",
            order_group: "order",
            data: {
                order_sn: n
            }
        }).then(function(e) {
            200 === e.data.code && wx.requestPayment(Object.assign({}, function(e) {
                for (var n = 1; n < arguments.length; n++) {
                    var o = null != arguments[n] ? arguments[n] : {};
                    n % 2 ? a(o, !0).forEach(function(a) {
                        (0, t.default)(e, a, o[a]);
                    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(o)) : a(o).forEach(function(t) {
                        Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(o, t));
                    });
                }
                return e;
            }({}, e.data.data.config), {
                timeStamp: e.data.data.config.timeStamp || e.data.data.config.timestamp,
                success: function() {
                    wx.hideLoading(), wx.showToast({
                        title: "支付成功",
                        mask: !0
                    }), o.getLists();
                },
                fail: function(t) {
                    console.log(t), wx.showModal({
                        title: "提示",
                        content: "支付失败",
                        showCancel: !1
                    });
                }
            }));
        });
    },
    getLists: function() {
        var a = this, n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1, o = this.data.active, s = {
            page: n,
            pageSize: 8,
            pay_status: o - 1
        };
        s.pay_status < 0 && delete s.pay_status, 3 == s.pay_status && (s.pay_status = -2), 
        4 == s.pay_status && (s.pay_status = -1), (0, e.getOrderLists)(s).then(function(e) {
            if (200 === e.data.code) {
                var s, i = e.data.data.list;
                a.setData((s = {}, (0, t.default)(s, "lists[".concat(o, "]"), n > 1 ? [].concat(a.data.lists[o], i) : i), 
                (0, t.default)(s, "pageTotal[".concat(o, "]"), e.data.data.count), (0, t.default)(s, "pageNum[".concat(o, "]"), n), 
                s));
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        wx.stopPullDownRefresh(), this.getLists();
    },
    onReachBottom: function() {
        var t = this.selectComponent("#pagination");
        if (!t) return !1;
        var e = t.hasMore();
        e && this.getLists(e);
    },
    onShareAppMessage: function() {}
});